package com.company.behavioral.state_pattern.concrete_state;

import com.company.behavioral.state_pattern.state.AccountState;

/**
 * 受限状态
 * @ClassName RestrictedState
 * @Author tiezheng.han
 * @Date 2020/9/7 14:04
 **/
public class RestrictedState extends AccountState {

    public RestrictedState(AccountState state){
        this.acc = state.acc;
    }

    @Override
    public void deposit(double amount) {
        acc.setBlanace(acc.getBlanace() + amount);
        stateCheck();
    }

    @Override
    public void withdraw(double amount) {
        System.out.println("账号受限，取款失败");
    }

    @Override
    public void computeInterest() {
        System.out.println("计算利息！");
    }

    @Override
    public void stateCheck() {
        if (acc.getBlanace() > 0){
            acc.setState(new NormalState(this));
        } else if (acc.getBlanace() > -2000){
            acc.setState(new OverdraftState(this));
        }
    }
}
